package com.sky.controller.user;


import com.sky.dto.ShoppingCartDTO;
import com.sky.entity.ShoppingCart;
import com.sky.result.Result;
import com.sky.service.ShoppingCartService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j  //日志 代替sout快捷键输出查看
@Api(tags = "购物车接口")
@RestController
@RequestMapping("/user/shoppingCart")
public class ShoppingCartController {
    @Autowired
    private ShoppingCartService shoppingCartService;

    @PostMapping("/add")
    @ApiOperation("添加购物车")
    public Result<String> add(@RequestBody ShoppingCartDTO shoppingCartDTO){
        log.info("添加菜品或套餐到购物车：{}",shoppingCartDTO);

        shoppingCartService.addShoppingCart(shoppingCartDTO);

        return Result.success();
    }

    @GetMapping("/list")
    @ApiOperation("回显购物车中数据")
    public Result<List<ShoppingCart>> list(){

        return Result.success(shoppingCartService.showShoppingCart());
    }

    @PostMapping("/sub")
    @ApiOperation("从购物车中减少或者删除单个菜品或套餐")
    public Result<String> update(@RequestBody ShoppingCartDTO shoppingCartDTO){
        log.info("从购物车中减少或者删除单个菜品或套餐：{}",shoppingCartDTO);
        shoppingCartService.update(shoppingCartDTO);
        return Result.success();
    }
    @DeleteMapping("/clean")
    @ApiOperation("清空购物车")
    public Result delete(@RequestBody ShoppingCartDTO shoppingCartDTO){
        log.info("清空购物车：{}",shoppingCartDTO);

        shoppingCartService.delete(shoppingCartDTO);

        return Result.success();
    }
}
